package cn.com.coldg.daoImpl;
import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import cn.com.coldg.bean.UserInfo;
import cn.com.coldg.bean.UserTeam;
import cn.com.coldg.dao.UserTeamDAO;
import cn.com.coldg.db.DatabaseConnection;


public class UserTeamDAOImpl implements UserTeamDAO{
	JdbcTemplate jdbc=new JdbcTemplate(DatabaseConnection.getDataSource());

	
	public boolean update(UserTeam team) {
		String sql="update UserTeam set teamName=? where Vid=?";
		Object[] args=new Object[]{team.getTeamName(),team.getVid()};
		boolean flag=false;
		int count=jdbc.update(sql, args);
		if(count>0)
			flag=true;
		return flag;
			
	}

	public boolean add(UserTeam team) {
			   String sql = "insert into userteam(TeamName)values(?)";
			   Object[] args=new Object[]{team.getTeamName()};
			   boolean flag=false;
			   int i=jdbc.update(sql, args);
			   if(i>0)
					flag=true;
			   return flag;
				
			
	}

	public UserTeam findById(int id) {
		String sql = "select * from UserTeam  where Vid = ?";
		Object[] args=new Object[]{id};
		UserTeam team=(UserTeam)jdbc.queryForObject(sql, args, new BeanPropertyRowMapper(UserTeam.class));
		return team;
	}

	public List<UserTeam> findAll() {
		String sql = "select Vid,TeamName from UserTeam";
		List<UserTeam> list = jdbc.query(sql,new BeanPropertyRowMapper(UserTeam.class));
		return list;
	}

	public boolean delete(int vid) {
		String sql="delete from userteam where vid=?";
		Object[] args = new Object[]{vid};
		boolean flag=false;
		int count=jdbc.update(sql, args);
		if(count>0)
			flag=true;
		return flag;
	}

	

}
